import request from "@/utils/request";

// 查询【请填写功能名称】列表
export function listFile(query) {
  return request({
    url: "/file/list",
    method: "get",
    params: query,
  });
}

// 删除【请填写功能名称】
export function delFile(id) {
  return request({
    url: "/file/?FileId=" + id,
    method: "delete",
  });
}

// 上传资料下载模块的文件
export function dataDownloadUploadFile(data) {
  return request({
    url: "/file/uploadfile",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}

// 上传公告、园区新闻的附件或上传图片文件
export function uploadFile(data) {
  const maxSizeInBytes = 50 * 1024 * 1024; // 50MB in bytes
  const file = data.get("file"); // Assuming the key for the file is "file"

  if (file.size > maxSizeInBytes) {
    window.alert("文件大小不能超过 50MB.");
    return Promise.reject("文件大小不能超过 50MB.");
  }
  return request({
    url: "/file/upload",
    method: "post",
    data,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
